package com.openbravo.pos.payment;

import aaaCasher.casherForm;

import com.attilax.io.pathx;
import com.attilax.ui.HTML5Form;
import com.attilax.ui.MsgBox;
import com.openbravo.format.Formats;
import com.openbravo.pos.customers.CustomerInfoExt;
import com.openbravo.pos.forms.AppLocal;
import com.openbravo.pos.forms.AppUser;
import com.openbravo.pos.forms.AppUserView;
import com.openbravo.pos.forms.AppView;
import com.openbravo.pos.forms.DataLogicSystem;

import java.awt.BorderLayout;
import java.awt.Button;
import java.awt.Color;
import java.awt.Component;
import java.awt.ComponentOrientation;
import java.awt.Container;
import java.awt.Dialog;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.Font;
import java.awt.Frame;
import java.awt.Insets;
import java.awt.Toolkit;
import java.awt.Window;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.swing.BorderFactory;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JRootPane;
import javax.swing.JTabbedPane;
import javax.swing.JToggleButton;
import javax.swing.UIDefaults;
import javax.swing.UIManager;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;

import org.eclipse.swt.widgets.Display;

public abstract class JPaymentSelect extends JDialog
  implements JPaymentNotifier
{
  private PaymentInfoList m_aPaymentInfo;
  private boolean printselected;
  private boolean accepted;
  private AppView app;
  private double m_dTotal;
  private CustomerInfoExt customerext;
  private DataLogicSystem dlSystem;
  private Map<String, JPaymentInterface> payments = new HashMap();
  private String m_sTransactionID;
  private JPanel jPanel1;
  private JPanel jPanel2;
  private JPanel jPanel3;
  private JPanel jPanel4;
  private JPanel jPanel5;
  private JPanel jPanel6;
  private JButton m_jButtonAdd;
  private JButton m_jButtonCancel;
  private JButton m_jButtonOK;
  private JToggleButton m_jButtonPrint;
  private JButton m_jButtonRemove;
  private JLabel m_jLblRemainingEuros;
  private JLabel m_jLblTotalEuros1;
  private JLabel m_jRemaininglEuros;
  private JTabbedPane m_jTabPayment;
  private JLabel m_jTotalEuros;

  protected JPaymentSelect(Frame paramFrame, boolean paramBoolean, ComponentOrientation paramComponentOrientation)
  {
    super(paramFrame, paramBoolean);
    initComponents();
    applyComponentOrientation(paramComponentOrientation);
    getRootPane().setDefaultButton(this.m_jButtonOK);
  }

  protected JPaymentSelect(Dialog paramDialog, boolean paramBoolean, ComponentOrientation paramComponentOrientation)
  {
    super(paramDialog, paramBoolean);
    initComponents();
    applyComponentOrientation(paramComponentOrientation);
  }

  public void init(AppView paramAppView)
  {
    this.app = paramAppView;
    this.dlSystem = ((DataLogicSystem)paramAppView.getBean("com.openbravo.pos.forms.DataLogicSystem"));
    this.printselected = true;
  }

  public void setPrintSelected(boolean paramBoolean)
  {
    this.printselected = paramBoolean;
  }

  public boolean isPrintSelected()
  {
    return this.printselected;
  }

  public List<PaymentInfo> getSelectedPayments()
  {
    return this.m_aPaymentInfo.getPayments();
  }

  public boolean showDialog(double paramDouble, CustomerInfoExt paramCustomerInfoExt)
  {
    this.m_aPaymentInfo = new PaymentInfoList();
    this.accepted = false;
    this.m_dTotal = paramDouble;
    this.customerext = paramCustomerInfoExt;
    this.m_jButtonPrint.setSelected(this.printselected);
    this.m_jTotalEuros.setText(Formats.CURRENCY.formatValue(new Double(this.m_dTotal)));
    // imp is  JPaymentSelectReceipt
    addTabs();
    
    // this.m_jTabPayment==== javax.swing.JTabbedPane
    if (this.m_jTabPayment.getTabCount() == 0)
    {
      this.m_aPaymentInfo.add(getDefaultPayment(paramDouble));
      this.accepted = true;
    }
    else
    {
      getRootPane().setDefaultButton(this.m_jButtonOK);
      printState();
      setVisible(true);
    }
    this.printselected = this.m_jButtonPrint.isSelected();
    this.m_jTabPayment.removeAll();
    return this.accepted;
  }

  protected abstract void addTabs();

  protected abstract void setStatusPanel(boolean paramBoolean1, boolean paramBoolean2);

  protected abstract PaymentInfo getDefaultPayment(double paramDouble);

  protected void setOKEnabled(boolean paramBoolean)
  {
    this.m_jButtonOK.setEnabled(paramBoolean);
  }

  protected void setAddEnabled(boolean paramBoolean)
  {
    this.m_jButtonAdd.setEnabled(paramBoolean);
  }

  protected void addTabPayment(JPaymentCreator paramJPaymentCreator)
  {
	//  this.app.getAppUserView().getUser().hasPermission(paramJPaymentCreator.getKey())
	//  paramJPaymentCreator.getKey()==  payment.cash
    if (true)
    {
      JPaymentInterface localJPaymentInterface = (JPaymentInterface)this.payments.get(paramJPaymentCreator.getKey());
      if (localJPaymentInterface == null)
      {
        localJPaymentInterface = paramJPaymentCreator.createJPayment();
        this.payments.put(paramJPaymentCreator.getKey(), localJPaymentInterface);
      }
      localJPaymentInterface.getComponent().applyComponentOrientation(getComponentOrientation());
      this.m_jTabPayment.addTab(AppLocal.getIntString(paramJPaymentCreator.getLabelKey()), new ImageIcon(getClass().getResource(paramJPaymentCreator.getIconKey())), localJPaymentInterface.getComponent());
    }
  }

  protected void setHeaderVisible(boolean paramBoolean)
  {
    this.jPanel6.setVisible(paramBoolean);
  }

  private void printState()
  {
    this.m_jRemaininglEuros.setText(Formats.CURRENCY.formatValue(new Double(this.m_dTotal - this.m_aPaymentInfo.getTotal())));
    this.m_jButtonRemove.setEnabled(!this.m_aPaymentInfo.isEmpty());
    this.m_jTabPayment.setSelectedIndex(0);
    ((JPaymentInterface)this.m_jTabPayment.getSelectedComponent()).activate(this.customerext, this.m_dTotal - this.m_aPaymentInfo.getTotal(), this.m_sTransactionID);
  }

  protected static Window getWindow(Component paramComponent)
  {
    if (paramComponent == null)
      return new JFrame();
    if (((paramComponent instanceof Frame)) || ((paramComponent instanceof Dialog)))
      return (Window)paramComponent;
    return getWindow(paramComponent.getParent());
  }

  public void setStatus(boolean paramBoolean1, boolean paramBoolean2)
  {
    setStatusPanel(paramBoolean1, paramBoolean2);
  }

  public void setTransactionID(String paramString)
  {
    this.m_sTransactionID = paramString;
  }

  private void initComponents()
  {
    this.jPanel4 = new JPanel();
    this.m_jLblTotalEuros1 = new JLabel();
    this.m_jTotalEuros = new JLabel();
    this.jPanel6 = new JPanel();
    this.m_jLblRemainingEuros = new JLabel();
    this.m_jRemaininglEuros = new JLabel();
    this.m_jButtonAdd = new JButton();
    this.m_jButtonRemove = new JButton();
    this.jPanel3 = new JPanel();
    this.m_jTabPayment = new JTabbedPane();
    this.jPanel5 = new JPanel();
    this.jPanel2 = new JPanel();
    this.m_jButtonPrint = new JToggleButton();
    this.jPanel1 = new JPanel();
    this.m_jButtonOK = new JButton();
    this.m_jButtonCancel = new JButton();
    setDefaultCloseOperation(2);
    setTitle(AppLocal.getIntString("payment.title"));
    setResizable(false);
    this.m_jLblTotalEuros1.setText(AppLocal.getIntString("label.totalcash"));
    this.jPanel4.add(this.m_jLblTotalEuros1);
    this.m_jTotalEuros.setBackground(Color.white);
    this.m_jTotalEuros.setFont(new Font("Dialog", 1, 14));
    this.m_jTotalEuros.setHorizontalAlignment(4);
    this.m_jTotalEuros.setBorder(BorderFactory.createCompoundBorder(BorderFactory.createLineBorder(UIManager.getDefaults().getColor("Button.darkShadow")), BorderFactory.createEmptyBorder(1, 4, 1, 4)));
    this.m_jTotalEuros.setOpaque(true);
    this.m_jTotalEuros.setPreferredSize(new Dimension(125, 25));
    this.m_jTotalEuros.setRequestFocusEnabled(false);
    this.jPanel4.add(this.m_jTotalEuros);
    this.jPanel6.setLayout(new FlowLayout(1, 5, 0));
    this.m_jLblRemainingEuros.setText(AppLocal.getIntString("label.remainingcash"));
    this.jPanel6.add(this.m_jLblRemainingEuros);
    this.m_jRemaininglEuros.setBackground(Color.white);
    this.m_jRemaininglEuros.setFont(new Font("Dialog", 1, 14));
    this.m_jRemaininglEuros.setHorizontalAlignment(4);
    this.m_jRemaininglEuros.setBorder(BorderFactory.createCompoundBorder(BorderFactory.createLineBorder(UIManager.getDefaults().getColor("Button.darkShadow")), BorderFactory.createEmptyBorder(1, 4, 1, 4)));
    this.m_jRemaininglEuros.setOpaque(true);
    this.m_jRemaininglEuros.setPreferredSize(new Dimension(125, 25));
    this.m_jRemaininglEuros.setRequestFocusEnabled(false);
    this.jPanel6.add(this.m_jRemaininglEuros);
    this.m_jButtonAdd.setIcon(new ImageIcon(getClass().getResource("/com/openbravo/images/btnplus.png")));
    this.m_jButtonAdd.addActionListener(new ActionListener()
    {
      public void actionPerformed(ActionEvent paramActionEvent)
      {
        JPaymentSelect.this.m_jButtonAddActionPerformed(paramActionEvent);
      }
    });
    this.jPanel6.add(this.m_jButtonAdd);
    this.m_jButtonRemove.setIcon(new ImageIcon(getClass().getResource("/com/openbravo/images/btnminus.png")));
    this.m_jButtonRemove.addActionListener(new ActionListener()
    {
      public void actionPerformed(ActionEvent paramActionEvent)
      {
        JPaymentSelect.this.m_jButtonRemoveActionPerformed(paramActionEvent);
      }
    });
    this.jPanel6.add(this.m_jButtonRemove);
    this.jPanel4.add(this.jPanel6);
    getContentPane().add(this.jPanel4, "North");
    this.jPanel3.setLayout(new BorderLayout());
    this.m_jTabPayment.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
    this.m_jTabPayment.setTabPlacement(2);
    this.m_jTabPayment.setFocusable(false);
    this.m_jTabPayment.setRequestFocusEnabled(false);
    this.m_jTabPayment.addChangeListener(new ChangeListener()
    {
      public void stateChanged(ChangeEvent paramChangeEvent)
      {
        JPaymentSelect.this.m_jTabPaymentStateChanged(paramChangeEvent);
      }
    });
    this.jPanel3.add(this.m_jTabPayment, "Center");
    getContentPane().add(this.jPanel3, "Center");
    this.jPanel5.setLayout(new BorderLayout());
    this.m_jButtonPrint.setIcon(new ImageIcon(getClass().getResource("/com/openbravo/images/fileprint.png")));
    this.m_jButtonPrint.setSelected(true);
    this.m_jButtonPrint.setFocusPainted(false);
    this.m_jButtonPrint.setFocusable(false);
    this.m_jButtonPrint.setMargin(new Insets(8, 16, 8, 16));
    this.m_jButtonPrint.setRequestFocusEnabled(false);
    this.jPanel2.add(this.m_jButtonPrint);
    this.jPanel2.add(this.jPanel1);
    this.m_jButtonOK.setIcon(new ImageIcon(getClass().getResource("/com/openbravo/images/button_ok.png")));
    this.m_jButtonOK.setText(AppLocal.getIntString("Button.OK"));
    this.m_jButtonOK.setFocusPainted(false);
    this.m_jButtonOK.setFocusable(false);
    this.m_jButtonOK.setMargin(new Insets(8, 16, 8, 16));
    this.m_jButtonOK.setRequestFocusEnabled(false);
    this.m_jButtonOK.addActionListener(new ActionListener()
    {
      public void actionPerformed(ActionEvent paramActionEvent)
      {
        JPaymentSelect.this.m_jButtonOKActionPerformed(paramActionEvent);
      }
    });
    this.jPanel2.add(this.m_jButtonOK);
    this.m_jButtonCancel.setIcon(new ImageIcon(getClass().getResource("/com/openbravo/images/button_cancel.png")));
    this.m_jButtonCancel.setText(AppLocal.getIntString("Button.Cancel"));
    this.m_jButtonCancel.setFocusPainted(false);
    this.m_jButtonCancel.setFocusable(false);
    this.m_jButtonCancel.setMargin(new Insets(8, 16, 8, 16));
    this.m_jButtonCancel.setRequestFocusEnabled(false);
    this.m_jButtonCancel.addActionListener(new ActionListener()
    {
      public void actionPerformed(ActionEvent paramActionEvent)
      {
        JPaymentSelect.this.m_jButtonCancelActionPerformed(paramActionEvent);
      }
    });
    this.jPanel2.add(this.m_jButtonCancel);
    
    //ati pb31 
		this.jPanel2.add(new JButton() {
			{
				this.setText("选择会员卡");
				this.addActionListener(new ActionListener() {

					@Override
					public void actionPerformed(ActionEvent arg0) {

						Runnable runnable_4form = new Runnable() {
							public void run() {
								HTML5Form fm = new HTML5Form(pathx
										.classPathParent_jensyegeor()
										+ "/user/list.html");

								fm.setSize(960, 550);
								fm.show();
								fm.forceActive();
							}
						};
						// runnable_4form.run();
						Display.getDefault().syncExec(runnable_4form);

					}
				});

			}

		});
    this.jPanel5.add(this.jPanel2, "After");
    getContentPane().add(this.jPanel5, "South");
    Dimension localDimension = Toolkit.getDefaultToolkit().getScreenSize();
    setBounds((localDimension.width - 672) / 2, (localDimension.height - 497) / 2, 672, 497);
  }

  private void m_jButtonRemoveActionPerformed(ActionEvent paramActionEvent)
  {
    this.m_aPaymentInfo.removeLast();
    printState();
  }

  private void m_jButtonAddActionPerformed(ActionEvent paramActionEvent)
  {
    PaymentInfo localPaymentInfo = ((JPaymentInterface)this.m_jTabPayment.getSelectedComponent()).executePayment();
    if (localPaymentInfo != null)
    {
      this.m_aPaymentInfo.add(localPaymentInfo);
      printState();
    }
  }

  private void m_jTabPaymentStateChanged(ChangeEvent paramChangeEvent)
  {
    if (this.m_jTabPayment.getSelectedComponent() != null)
      ((JPaymentInterface)this.m_jTabPayment.getSelectedComponent()).activate(this.customerext, this.m_dTotal - this.m_aPaymentInfo.getTotal(), this.m_sTransactionID);
  }

  private void m_jButtonOKActionPerformed(ActionEvent paramActionEvent)
  {
//	  MsgBox.show("pb31a");
    PaymentInfo localPaymentInfo = ((JPaymentInterface)this.m_jTabPayment.getSelectedComponent()).executePayment();
    if (localPaymentInfo != null)
    {
      this.m_aPaymentInfo.add(localPaymentInfo);
      this.accepted = true;
      dispose();
    }
  }

  private void m_jButtonCancelActionPerformed(ActionEvent paramActionEvent)
  {
    dispose();
  }

  public class JPaymentMagcardRefundCreator
    implements JPaymentSelect.JPaymentCreator
  {
    public JPaymentMagcardRefundCreator()
    {
    }

    public JPaymentInterface createJPayment()
    {
      return new JPaymentMagcard(JPaymentSelect.this.app, JPaymentSelect.this);
    }

    public String getKey()
    {
      return "refund.magcard";
    }

    public String getLabelKey()
    {
      return "tab.magcard";
    }

    public String getIconKey()
    {
      return "/com/openbravo/images/vcard.png";
    }
  }

  public class JPaymentPaperRefundCreator
    implements JPaymentSelect.JPaymentCreator
  {
    public JPaymentPaperRefundCreator()
    {
    }

    public JPaymentInterface createJPayment()
    {
      return new JPaymentRefund(JPaymentSelect.this, "paperout");
    }

    public String getKey()
    {
      return "refund.paper";
    }

    public String getLabelKey()
    {
      return "tab.paper";
    }

    public String getIconKey()
    {
      return "/com/openbravo/images/knotes.png";
    }
  }

  public class JPaymentChequeRefundCreator
    implements JPaymentSelect.JPaymentCreator
  {
    public JPaymentChequeRefundCreator()
    {
    }

    public JPaymentInterface createJPayment()
    {
      return new JPaymentRefund(JPaymentSelect.this, "chequerefund");
    }

    public String getKey()
    {
      return "refund.cheque";
    }

    public String getLabelKey()
    {
      return "tab.chequerefund";
    }

    public String getIconKey()
    {
      return "/com/openbravo/images/desktop.png";
    }
  }

  public class JPaymentCashRefundCreator
    implements JPaymentSelect.JPaymentCreator
  {
    public JPaymentCashRefundCreator()
    {
    }

    public JPaymentInterface createJPayment()
    {
      return new JPaymentRefund(JPaymentSelect.this, "cashrefund");
    }

    public String getKey()
    {
      return "refund.cash";
    }

    public String getLabelKey()
    {
      return "tab.cashrefund";
    }

    public String getIconKey()
    {
      return "/com/openbravo/images/cash.png";
    }
  }

  public class JPaymentDebtCreator
    implements JPaymentSelect.JPaymentCreator
  {
    public JPaymentDebtCreator()
    {
    }

    public JPaymentInterface createJPayment()
    {
      return new JPaymentDebt(JPaymentSelect.this);
    }

    public String getKey()
    {
      return "payment.debt";
    }

    public String getLabelKey()
    {
      return "tab.debt";
    }

    public String getIconKey()
    {
      return "/com/openbravo/images/kdmconfig32.png";
    }
  }

  public class JPaymentFreeCreator
    implements JPaymentSelect.JPaymentCreator
  {
    public JPaymentFreeCreator()
    {
    }

    public JPaymentInterface createJPayment()
    {
      return new JPaymentFree(JPaymentSelect.this);
    }

    public String getKey()
    {
      return "payment.free";
    }

    public String getLabelKey()
    {
      return "tab.free";
    }

    public String getIconKey()
    {
      return "/com/openbravo/images/package_toys.png";
    }
  }

  public class JPaymentMagcardCreator
    implements JPaymentSelect.JPaymentCreator
  {
    public JPaymentMagcardCreator()
    {
    }

    public JPaymentInterface createJPayment()
    {
      return new JPaymentMagcard(JPaymentSelect.this.app, JPaymentSelect.this);
    }

    public String getKey()
    {
      return "payment.magcard";
    }

    public String getLabelKey()
    {
      return "tab.magcard";
    }

    public String getIconKey()
    {
      return "/com/openbravo/images/vcard.png";
    }
  }

  public class JPaymentPaperCreator
    implements JPaymentSelect.JPaymentCreator
  {
    public JPaymentPaperCreator()
    {
    }

    public JPaymentInterface createJPayment()
    {
      return new JPaymentPaper(JPaymentSelect.this, "paperin");
    }

    public String getKey()
    {
      return "payment.paper";
    }

    public String getLabelKey()
    {
      return "tab.paper";
    }

    public String getIconKey()
    {
      return "/com/openbravo/images/knotes.png";
    }
  }

  public class JPaymentChequeCreator
    implements JPaymentSelect.JPaymentCreator
  {
    public JPaymentChequeCreator()
    {
    }

    public JPaymentInterface createJPayment()
    {
      return new JPaymentCheque(JPaymentSelect.this);
    }

    public String getKey()
    {
      return "payment.cheque";
    }

    public String getLabelKey()
    {
      return "tab.cheque";
    }

    public String getIconKey()
    {
      return "/com/openbravo/images/desktop.png";
    }
  }

  public class JPaymentCashCreator
    implements JPaymentSelect.JPaymentCreator
  {
    public JPaymentCashCreator()
    {
    }

    public JPaymentInterface createJPayment()
    {
      return new JPaymentCashPos(JPaymentSelect.this, JPaymentSelect.this.dlSystem);
    }

    public String getKey()
    {
      return "payment.cash";
    }

    public String getLabelKey()
    {
      return "tab.cash";
    }

    public String getIconKey()
    {
      return "/com/openbravo/images/cash.png";
    }
  }

  public static abstract interface JPaymentCreator
  {
    public abstract JPaymentInterface createJPayment();

    public abstract String getKey();

    public abstract String getLabelKey();

    public abstract String getIconKey();
  }
}

/* Location:           D:\PowerFulPOS-2.30.2\openbravopos.jar
 * Qualified Name:     com.openbravo.pos.payment.JPaymentSelect
 * JD-Core Version:    0.6.0
 */